//
//  ActivityViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/6/27.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "ActivityViewController.h"
#import "ActivityView.h"
#import "ActivityViewCell.h"
#import "ActivityModel.h"
#import "ActivityDetailViewController.h"

@interface ActivityViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView * tableView;

@property (nonatomic, strong)NSArray<ActivityModel *>* listModelArray;

@end

@implementation ActivityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"活动";
    
    [ActivityModel activityModelWithSucess:^(NSArray<ActivityModel *> *array) {
        
        self.listModelArray = array;
        
    } error:^{
        
//        NSLog(@"==");
    }];
    
    [self setupUI];
}


- (void)setListModelArray:(NSArray<ActivityModel *> *)listModelArray{
    
    _listModelArray = listModelArray;
    
    [self.tableView reloadData];
}


- (void)setupUI{
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    
    ActivityView * activityView = [[ActivityView alloc] initWithFrame:self.view.bounds];
    
    [self.view addSubview:activityView];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerClass:[ActivityViewCell class] forCellReuseIdentifier:@"ActivityCell"];
    
    [self.view addSubview:self.tableView];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.listModelArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
     ActivityViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ActivityCell" forIndexPath:indexPath];
    
    cell.model = self.listModelArray[indexPath.row];
    
    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 170 * SCREENH6;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    self.hidesBottomBarWhenPushed = YES;
    
    ActivityViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    
    ActivityDetailViewController * detailVC = [ActivityDetailViewController new];
    
    detailVC.ID = cell.ID;
    
    [self.navigationController pushViewController:detailVC animated:YES];
    
    self.hidesBottomBarWhenPushed = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
